
type colorType = 'info' | 'primary' | 'success' | 'warning' | 'error'

type printInfoType = {
    title: string,
    type: colorType,
    text: string,
    plain: boolean
}
/**
 * @des: 打印状态到控制台
 * @param {*} param1
 * @return {*}
 */
export const printInfo = ({ title = 'log', type = 'info', text = '', plain = false }) => {
    if (!plain) {
        window.console.log(`%c ${title} %c ${text} %c `, `background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;`, `padding: 1px; border-radius: 0 3px 3px 0;  color: #fff;background:${getTypeColor(type as colorType)};`, `background:transparent`)
    }
    else {
        window.console.log(`%c ${title} ${text}`, `padding: 1px;;color:${getTypeColor(type as colorType)};`)
    }
}

/**
 * @des: 获取对应状态的颜色
 * @param {colorType} type
 * @return {*}
 */
export const getTypeColor = (type: any) => {
    switch (type) {
        case 'info':
            return '#909399';
        case 'primary':
            return '#409EFF';
        case 'success':
            return '#67C23A';
        case 'warning':
            return '#E6A23C';
        case 'error':
            return '#F56C6C';
        default:
            return '#909399';
    }
}

const log = {
    install(app: any) {
        if (app) app.config.globalProperties.$log = printInfo
    }
}

export default log
